package code.structure.module.signIn
{
	import code.main.AppCommonView;
	import code.main.core.mvc.YController;
	import code.structure.manager.assist.ProjectAssistManager;
	import code.structure.module.signIn.view.SignInEntryIcon;
	import code.structure.module.signIn.view.SignInView;
	import code.untils.CommandNameConst;
	
	import com.patience.mvc.context.Command;

	/**
	 *签到控制器 
	 * @author liangqian
	 * 
	 */	
	public class SignInController extends YController
	{
		private var _signInModel:SignInModel;
		private var _signInEntryIcon:SignInEntryIcon;
		private var _signInView:SignInView;
		public function SignInController()
		{
			super();
		}
		
		override public function start():void
		{
			super.start();
			_signInModel = new SignInModel();
			register(CommandNameConst.COMMAND_SIGN_DATA_ANALY_COMPLETE,commandHandler);
		}
		
		private function commandHandler(c:Command):void
		{
			switch(c.cmdName)
			{
				case CommandNameConst.COMMAND_SIGN_DATA_ANALY_COMPLETE:
					_signInEntryIcon = new SignInEntryIcon((_context.commonView as AppCommonView).appContainer.uiLayer,showSignInViewHandler)
					break;
			}
		}
		
		private function showSignInViewHandler():void
		{
			if(_signInView == null)
				_signInView = new SignInView(this);
			ProjectAssistManager.getIntance().popManager.showWindow(_signInView);
			_signInView.setData(_signInModel.startTime,_signInModel.signedList);
			_signInView.totalRewardList = _signInModel.totalRewardList;
		}
		/**
		 *签到签当天 
		 * @param day
		 * 
		 */		
		public function signInHandler(day:int):void
		{
			_signInModel.signInHandler(day);
			_signInView.setData(_signInModel.startTime,_signInModel.signedList);
		}
		
		/**
		 *补签 
		 * @param day
		 * 
		 */		
		public function signInOffsetHandler(day:int):void
		{
			_signInModel.signInOffsetHandler(day);
			_signInView.setData(_signInModel.startTime,_signInModel.signedList);
		}
		/**
		 *领累积签到的奖励 
		 * @param day 累积签到的天数
		 * 
		 */		
		public function receiveReward(day:int):void
		{
			_signInModel.receiveReward(day);
		}
	}
}